package com.iw.test.db;

import java.util.List;

import javax.annotation.Resource;

import org.junit.Test;

import com.iw.core.orm.Filtration;
import com.iw.core.orm.Filtration.MatchType;
import com.iw.core.security.entity.Resources;
import com.iw.core.security.entity.Users;
import com.iw.core.security.service.ResourcesService;
import com.iw.core.security.service.UsersService;

public class JUsersAction extends DBBase {
	@Resource
	private UsersService usersService;
	@Resource
	private ResourcesService resourcesService;

	@Test
	public void list() {
		List<Users> list = usersService.findList("from Users");
		System.out.println("-----------------------------------");
		for (Users u : list) {
			System.out.println(u.getAccount());
		}
	}

	@Test
	public void criteria() {
		Filtration filter = new Filtration(MatchType.EQ, 1, "group.id");
		// Filtration filter = new Filtration(MatchType.EQ, "公用模块", "group.name");
		List<Resources> list = resourcesService.findList(filter);
		for (Resources r : list) {
			System.out.println(r.getName());
		}
	}

	@Test
	public void criteriaUser() {
		Filtration filter = new Filtration(MatchType.EQ, true, "visible");
		// Filtration filter = new Filtration(MatchType.LIKE, "公用模块", "group.name");
		List<Users> list = usersService.findList(filter);
		for (Users r : list) {
			System.out.println(r.getName());
		}
	}

	@Test
	public void tKdcoder() {
		String s = "group.name";
		String s1 = s.substring(0, s.indexOf("."));
		String s2 = s.substring(s.indexOf(".") + 1);
		System.out.println(s1);
		System.out.println(s2);

	}
}
